use serde::{Deserialize, Serialize};

use crate::graph::value::Value;

use super::{Input, NodeTrait, Output};

#[derive(Clone, Serialize, Deserialize)]
pub struct BlackboardOutRefNode {
    pub name: String,
    pub value: Value,
    inputs: Vec<Input>,
    outputs: Vec<Output>,
}

impl BlackboardOutRefNode {
    pub fn new(value: Value) -> Self {
        Self {
            name: "引用".to_string(),
            value: value.clone(),
            inputs: vec![Input {
                name: "Ref".to_string(),
                description: Some("引用接口".to_string()),
                value
            }],
            outputs: vec![],
        }
    }
}

impl NodeTrait for BlackboardOutRefNode {
    fn name(&self) ->  &str {
        &self.name
    }

    fn ty(&self) ->  &str {
        "__BLACKBOARD_OUT_REF_NODE__"
    }

    fn description(&self) -> Option<&str> {
        Some("黑板输出引用节点")
    }

    fn inputs(&self) ->  &[Input] {
        &self.inputs
    }

    fn outputs(&self) ->  &[Output] {
        &self.outputs
    }

    fn has_children(&self) -> bool {
        false
    }

    fn inputs_mut(&mut self) ->  &mut Vec<Input> {
        &mut self.inputs
    }

    fn outputs_mut(&mut self) ->  &mut Vec<Output> {
        &mut self.outputs
    }

    fn draw_name(&mut self,ui: &mut egui::Ui) -> bool {
        ui.text_edit_singleline(&mut self.name).changed()
    }

    fn can_copy(&self) -> bool {
        false
    }
}
